package com.jscloud.bigdata;


import org.junit.Before;
import org.junit.Test;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.*;

public class PhoenixSearch {
        /**
         * 定义phoenix的url地址
         * connection
         * 构建Statement对象
         * 定义查询的sql语句,一定注意大小写
         * 构建好的对象执行sql语句
         */
        private Statement statement;
        private ResultSet rs;
        private Connection connection;

        @Before
        public void init() throws SQLException {
                //定义phoenix的url地址
                String url = "jdbc:phoenix:bigdata02:2181";
                // connection
                connection = DriverManager.getConnection(url);
                //构建Statement对象
                statement = connection.createStatement();


        }

        @Test
        public void queryTable() throws SQLException {
                //定义查询的sql语句,一定注意大小写
                String sql="select * from USER_PHOENIX";
                //执行sql语句
                try {
                        rs=statement.executeQuery(sql);
                        while(rs.next()){
                                System.out.println("city:"+rs.getString("city"));
                                System.out.println("POPULATION :"+rs.getString("POPULATION"));
                                System.out.println("STATE:"+rs.getString("STATE"));
                                System.out.println("-------------------------");
                        }
                } catch (SQLException e) {
                        e.printStackTrace();
                } finally {
                        if (connection != null) {
                                connection.close();
                        }
                }
        }
}